<template>
  <swiper>
    <swiper-item v-for="(item, index) in banners"
                 :key='index'>
      <a :href="item.link">
        <img :src="item.image"
             alt=""
             @load="imgLoad">
      </a>
    </swiper-item>
  </swiper>
</template>

<script>
  import { Swiper, SwiperItem } from 'components/common/swiper'

  export default {
    name: "HomeSwiper",
    data () {
      return {
        isImgLoad: false
      }
    },
    components: {
      Swiper,
      SwiperItem
    },
    props: {
      banners: {
        type: Array,
        default() {
          return []
        }
      }
    },
    methods: {
      imgLoad() {
        // 监视图片是否已加载（至少一张）
        if (!this.isImgLoad) {
          this.isImgLoad = true
          return this.$emit('imgLoad')
        }
      }
    }
  }
</script>

<style scoped>
</style>
